<template>
  <base-breadcrumb :breadcrumb="!isAudit">
    <a-card class="mb20" :loading="loading">
      <titleName title="基本信息"></titleName>
      <a-form-model
        ref="ruleForm"
        :model="form"
        :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }"
        :wrapperCol="{ lg: { span: 16 }, sm: { span: 16 } }"
      >
        <a-row :gutter="24">
          <a-col :md="8" :sm="8">
            <a-form-model-item label="所属单位">
              <BaseInput disabled placeholder="加载中" v-model="form.viewName"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="作业时间">
              <BaseInput disabled placeholder="加载中" v-model="form.workDate"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="作业班组">
              <BaseInput disabled placeholder="加载中" v-model="form.teamName"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="分包单位">
              <BaseInput disabled placeholder="加载中" v-model="form.subcontractName"></BaseInput>
            </a-form-model-item>
          </a-col>

          <a-col :md="8" :sm="8">
            <a-form-model-item label="施工具体部位">
              <BaseInput disabled placeholder="加载中" :value="getArea()"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="申请人">
              <BaseInput disabled placeholder="加载中" v-model="form.creatorName"></BaseInput>
            </a-form-model-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-model-item label="申请时间">
              <BaseInput disabled placeholder="加载中" v-model="form.createTime"></BaseInput>
            </a-form-model-item>
          </a-col>
          <template v-for="item in form.dangerBasicInformationList">
            <a-col :md="8" :sm="8" v-if="item.name">
              <a-form-model-item :label="item.name">
                <BaseInput v-if="item.dangerType ==='SINGLE_LINE'" disabled :title="item.input" v-model="item.input" />
                <BaseInput v-if="item.dangerType ==='MULTIPLE_LINES'" :title="item.input" disabled
                           v-model="item.input"
                />
                <BaseInputNumber v-if="item.dangerType ==='NUMBER_INPUT'" disabled :title="item.input"
                                 v-model="item.input"
                />
                <BaseInput v-if="item.dangerType ==='SINGLE_SELECTION'" disabled :value="item.input=='true'?'是':'否'" />
                <template v-if="item.dangerType ==='MULTIPLE_SELECTION'">
                  <a-checkbox default-checked disabled v-for="v in item.input.split(',')">{{ v }}</a-checkbox>
                </template>
                <BaseInput v-if="item.dangerType ==='LOCATE'" disabled :title="item.input" v-model="item.input" />
                <template v-if="item.dangerType ==='WORKER'">
                  <a-tag v-for="v in getList(form.workName)">{{ v }}</a-tag>
                </template>
                <template v-if="item.dangerType ==='MANAGER'">
                  <a-tag v-for="v in getList(form.managerName)">{{ v }}</a-tag>
                </template>
                <BaseInput v-if="item.dangerType ==='CONSTRUCTION_AREA'" disabled :title="item.input"
                           v-model="item.input"
                />
                <BaseTextarea v-if="item.dangerType ==='PROTECTIVE_EQUIPMENT'" disabled :title="item.input"
                              v-model="item.data"
                />

                <!--          气体监测-->
                <!--                          <div v-if="item.type=='GAS_DETECTION'" >-->
                <!--                            <van-cell-group v-for="items in item.gasInformationVOS" :key="items.id">-->
                <!--                              <van-cell  class="basic" @click="gotoGasDetails(items)" is-link :value="items.gasDate"></van-cell>-->
                <!--                            </van-cell-group>-->
                <!--                          </div>-->
              </a-form-model-item>
            </a-col>

          </template>

          <a-col :md="24" :sm="24" v-if="form.employees.length > 0">
            <titleName title="现场操作人员"></titleName>
            <s-table
              bordered
              ref="table"
              size="default"
              rowKey="key"
              :columns="columns"
              :data="loadData"
              :alert="true"
              :showPagination="false"
            >
              <span slot="workTypeName" slot-scope="text, record">{{ record.workTypeName || '无' }}</span>
            </s-table>
          </a-col>
          <a-col
            :md="24"
            :sm="24"
            class="mt20"
            v-if="form.majorSecurityList && form.majorSecurityList.length > 0"
          >
            <titleName title="主要安全措施 "></titleName>
            <h3 v-for="(i, index) in form.majorSecurityList" :key="i.id">
              {{ index + 1 }}: {{ i.name
              }}<span class="ml20" style="color: rgb(243, 45, 45)">{{ i.type == 1 ? '是' : '否' }}</span>
            </h3>
          </a-col>
          <a-col :md="24" :sm="24" class="mt20" v-if="form.protection.lifeLine != null">
            <titleName title="个人防护器材 "></titleName>
            <a-row>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.lifeLine"> 救生索</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.fireExtinguisher"> 灭火器</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.seatBelt"> 安全带</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.respiratory"> 呼吸器</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.lighting"> 防爆照明灯</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.dustMask"> 防尘口罩</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.liftDevice"> 提升设备</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.communication"> 通讯设备</a-checkbox>
              </a-col>
              <a-col :span="6">
                <a-checkbox disabled :checked="form.protection.otherEquipment">
                  其他防护器材
                </a-checkbox>
              </a-col>

              <a-col :span="6">
                <!-- <a-form-model-item label="其他输入的"> -->
                <BaseInput
                  disabled
                  placeholder="其他输入的"
                  v-model="form.protection.input"
                ></BaseInput>
                <!-- </a-form-model-item> -->
              </a-col>
            </a-row>
          </a-col>
          <a-col :md="24" :sm="24" class="mt20" v-if="form.gasInformationServiceVOS.length > 0">
            <titleName title="气体检测"></titleName>
            <s-table
              bordered
              ref="table1"
              size="default"
              rowKey="key"
              :columns="columns1"
              :data="loadData1"
              :alert="true"
              :showPagination="false"
            ></s-table>
          </a-col>
        </a-row>
      </a-form-model>
      <titleName class="mt20" title="照片"></titleName>
      <l-table
        v-if="form.fileInfoList && form.fileInfoList.length"
        :upload-arrys.sync="form.fileInfoList"
        business-code="MM16"
        upload-type="image"
        edit-model="2"
        disabled
      />
      <span v-else>无</span>
    </a-card>
    <div class="tool-btns page-btn-right-top">
      <BasePrintButton
        v-if="checkVisibleInDetail && form.auditStatus === 'PAST'"
        type="primary"
        :beforePrintFn="getDetailsPrintReq"
      />
      <a-button @click="handleClose" v-if="checkVisibleInDetail && !isConsultation">关闭</a-button>
    </div>
  </base-breadcrumb>
</template>
<script>
import SelectSubCompany from '@/components/Select/SelectSubCompany' // 分公司
import SelectProject from '@/components/Select/SelectProject' // 分公司
import { STable } from '@/components'
import { checkVisibleInDetail } from '@/utils/util'
import { getDetails, getDetailsPrint } from '@/api/safetySupervision/dangerousOperations'
import BasePrintButton from '@/components/BasePrintButton' // 打印按钮
const columns = [
  {
    title: '姓名',
    dataIndex: 'name'
  },
  {
    title: '工种',
    dataIndex: 'workTypeName',
    scopedSlots: { customRender: 'workTypeName' }
  },
  {
    title: '电话号码',
    dataIndex: 'phone'
  }
]
const columns1 = [
  {
    title: '时间',
    dataIndex: 'gasDate'
  },
  {
    title: '氧含量',
    dataIndex: 'oxygenContent'
  },
  {
    title: '可燃气体',
    dataIndex: 'combustibleGas'
  },
  {
    title: '一氧化碳',
    dataIndex: 'carbonMonoxide'
  },
  {
    title: '其它化学品',
    dataIndex: 'otherChemicals'
  },
  {
    title: '允许范围',
    dataIndex: 'allowRange'
  }
]
export default {
  name: 'a' + Date.now(),
  components: {
    STable,
    SelectSubCompany,
    SelectProject,
    BasePrintButton
  },
  props: {
    isAudit: {
      // 是否作为审批详情
      type: Boolean,
      default: false
    },
     // 是否作为意见征询
    isConsultation: {
        type: Boolean,
        default: false
    }
  },
  data() {
    this.columns = columns
    this.columns1 = columns1
    return {
      checkVisibleInDetail: checkVisibleInDetail(this),
      form: { employees: [], protection: {}, gasInformationServiceVOS: [], fileInfoList: [], viewName: "" },
      id: '',
      loading: false,
      loadData: () => {
        return new Promise((resolve, reject) => {
          resolve({
            data: this.form.employees
          })
        })
      },
      loadData1: () => {
        return new Promise((resolve, reject) => {
          resolve({
            data: this.form.gasInformationServiceVOS
          })
        })
      }
    }
  },
  created() {
    this.id = this.$route.query.id
    this.$route.meta.title = '危险作业详情'
    this.getDetail()
  },
  methods: {
    getArea() {
      let temp = this.form.areaName
      if (this.form.areaRemark) {
        temp += '(' + this.form.areaRemark + ')'
      }
      return temp
    },
    getList(list) {
      if (!list) return []
      return list.map(v => v.name)
    },
    getDetailsPrintReq() {
      const { id } = this.$route.query
      if (!id) return
      const params = {
        id
      }
      return getDetailsPrint(params).then((res) => {
        console.log(res)
        return res[1].data.content
      })
    },
    async getDetail() {
      this.loading = true
      const [err, res] = await getDetails({ id: this.id })
      this.loading = false
      if (!err) {
        if (res.data.majorSecurityList == null) {
          res.data.majorSecurityList = []
        }
        res.data.constructionSite = res.data.constructionSite || '无'
        this.form = res.data
        this.form.viewName = this.form.branchComName + '/' + this.form.projectName
      }
    },
    handleClose() {
      if (this.isAudit) {
        window.close()
      } else {
        this.$multiTab.close(this.$route.fullpath)
      }
    }
  }
}
</script>
<style lang="less">
.foot-btn {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 20px;
  color: rgb(243, 45, 45);
}
</style>
